---
title: Toggle
description: A two-state button that can be on or off.

links:
  doc: https://base-ui.com/react/components/toggle#api-reference
---

<ComponentPreview name="p-toggle-1" />

## Installation

<CodeTabs>

<TabsList>
  <TabsTab value="cli">CLI</TabsTab>
  <TabsTab value="manual">Manual</TabsTab>
</TabsList>
<TabsPanel value="cli">

```bash
npx shadcn@latest add @coss/toggle
```

</TabsPanel>

<TabsPanel value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install @base-ui-components/react
```

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="toggle" title="components/ui/toggle.tsx" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsPanel>

</CodeTabs>

## Usage

```tsx
import { Toggle } from "@/components/ui/toggle"
```

```tsx
<Toggle>Toggle</Toggle>
```

## Examples

### Outline

<ComponentPreview name="p-toggle-2" />

### With Icon

<ComponentPreview name="p-toggle-3" />

### Small Size

<ComponentPreview name="p-toggle-4" />

### Large Size

<ComponentPreview name="p-toggle-5" />

### Disabled

<ComponentPreview name="p-toggle-6" />

### Icon Group

<ComponentPreview name="p-toggle-7" />

## Comparing with Radix / shadcn

If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with **coss ui** quickly.

### Quick Checklist

- If you used `asChild` on parts, switch to the `render` prop

### Additional Notes

**Size Comparison**

**coss ui** toggle sizes are more compact compared to shadcn/ui, making them better suited for dense applications:

| Size      | Height (shadcn/ui) | Height (coss ui) |
| --------- | ------------------ | ---------------- |
| `sm`      | 32px               | 28px             |
| `default` | 36px               | 32px             |
| `lg`      | -                  | 36px             |

So, for example, if you were using the `default` size in shadcn/ui and you want to preserve the original height, you should use the `lg` size in coss ui.
